home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 May / CMCD0504.ISO / Software / Freeware / Programare / gdiplusdelphi / demos / Using a Pen to Draw Lines and Shapes / Setting Pen Width and Alignment / GDITEST28.dpr
Encoding:
Text File  |  2003-10-15  |  2.5 KB  |  94 lines

  1. program GDITEST28;
  2.  
  3. uses
  4.   Windows,
  5.   Messages,
  6.   SysUtils,
  7.   GDIPAPI,
  8.   GDIPOBJ;
  9.  
  10. Procedure OnPaint(DC: HDC);
  11. var
  12.   graphics : TGPGraphics;
  13.   blackPen, greenPen: TGPPen;
  14. begin
  15.   graphics := TGPGraphics.Create(DC);
  16.   blackPen:= TGPPen.Create(MakeColor(255, 0, 0, 0),1);
  17.   greenPen:= TGPPen.Create(MakeColor(255, 0, 255, 0),10);
  18.   greenPen.SetAlignment(PenAlignmentCenter);
  19.   // Draw the line with the wide green pen.
  20.   graphics.DrawLine(greenPen, 10, 100, 100, 50);
  21.  // Draw the same line with the thin black pen.
  22.   graphics.DrawLine(blackPen, 10, 100, 100, 50);
  23.   blackPen.Free;
  24.   greenPen.Free;
  25.   graphics.Free;
  26. end;
  27.  
  28.  
  29. function WndProc(Wnd : HWND; message : UINT; wParam : Integer; lParam: Integer) : Integer; stdcall;
  30. var
  31.   Handle: HDC;
  32.   ps: PAINTSTRUCT;
  33. begin
  34.   case message of
  35.     WM_PAINT:
  36.       begin
  37.         Handle := BeginPaint(Wnd, ps);
  38.         OnPaint(Handle);
  39.         EndPaint(Wnd, ps);
  40.         result := 0;
  41.       end;
  42.  
  43.     WM_DESTROY:
  44.       begin
  45.         PostQuitMessage(0);
  46.         result := 0;
  47.       end;
  48.  
  49.    else
  50.       result := DefWindowProc(Wnd, message, wParam, lParam);
  51.    end;
  52. end;
  53.  
  54. var
  55.   hWnd     : THandle;
  56.   Msg      : TMsg;
  57.   wndClass : TWndClass;
  58. begin
  59.    wndClass.style          := CS_HREDRAW or CS_VREDRAW;
  60.    wndClass.lpfnWndProc    := @WndProc;
  61.    wndClass.cbClsExtra     := 0;
  62.    wndClass.cbWndExtra     := 0;
  63.    wndClass.hInstance      := hInstance;
  64.    wndClass.hIcon          := LoadIcon(0, IDI_APPLICATION);
  65.    wndClass.hCursor        := LoadCursor(0, IDC_ARROW);
  66.    wndClass.hbrBackground  := HBRUSH(GetStockObject(WHITE_BRUSH));
  67.    wndClass.lpszMenuName   := nil;
  68.    wndClass.lpszClassName  := 'GettingStarted';
  69.  
  70.    RegisterClass(wndClass);
  71.  
  72.    hWnd := CreateWindow(
  73.       'GettingStarted',       // window class name
  74.       'Setting Pen Width and Alignment',      // window caption
  75.       WS_OVERLAPPEDWINDOW,    // window style
  76.       Integer(CW_USEDEFAULT), // initial x position
  77.       Integer(CW_USEDEFAULT), // initial y position
  78.       Integer(CW_USEDEFAULT), // initial x size
  79.       Integer(CW_USEDEFAULT), // initial y size
  80.       0,                      // parent window handle
  81.       0,                      // window menu handle
  82.       hInstance,              // program instance handle
  83.       nil);                   // creation parameters
  84.  
  85.    ShowWindow(hWnd, SW_SHOW);
  86.    UpdateWindow(hWnd);
  87.  
  88.    while(GetMessage(msg, 0, 0, 0)) do
  89.    begin
  90.       TranslateMessage(msg);
  91.       DispatchMessage(msg);
  92.    end;
  93. end.
  94.